/**
 * @param {number[][]} isConnected
 * @return {number}
 */
var findCircleNum = function (isConnected) {
  let count = 0
  let rows = isConnected.length
  let visited = new Set()
  for (let i = 0; i < rows; i++) {
    if (!visited.has(i)) {
      count++
      dfs(visited, isConnected, rows, i)
    }
  }
  return count
};
function dfs (visited, isConnected, rows, i) {
  for (let j = 0; j < rows; j++) {
    if (isConnected[i][j] == 1 && !visited.has(j)) {
      visited.add(j)
      dfs(visited, isConnected, rows, j)
    }
  }
}